package com.test.session;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * @description 多个线程getcurrentthread
 * @author Leon Plious
 * @date 2020年7月6日
 */
public class HibernateTestSessionMulThread {

	static Session session1;
	static Session session2;
	
	public static void main(String[] args) throws InterruptedException {
		
		SessionFactory sf = new Configuration().configure().buildSessionFactory();
		
		// 一个线程开辟一个session
		Thread t1 = new Thread() {
			
			@Override
			public void run() {
				session1 = sf.getCurrentSession();
			}
		};
		t1.start();
		
		Thread t2 = new Thread() {
			
			@Override
			public void run() {
				session2 = sf.getCurrentSession();
			}
		};
		t2.start();
		
		t1.join();
		t2.join();
		
		System.out.println(session1 == session2);
	}
}
